//
//  BaseTabBarController.m
//  AllKnows
//
//  Created by lanou on 15/12/17.
//  Copyright © 2015年 Zero. All rights reserved.
//

#import "BaseTabBarController.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FourthViewController.h"

@interface BaseTabBarController ()

//顶部topView
@property (nonatomic,strong) UIView * topView;

//topView 左侧按钮
@property (nonatomic,strong) UIButton *  leftButton;

@end

@implementation BaseTabBarController

//设置顶部view
- (void)setTopView
{
    
    self.topView = [[UIView alloc]initWithFrame:(CGRectMake(0, 0,KWidth , 55))];
    
    self.topView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:0.9];
    
    
    self.leftButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    self.leftButton.frame = CGRectMake(5, 20, 30, 30);
    self.leftButton.backgroundColor = [UIColor blackColor];
    [self.leftButton addTarget:self action:@selector(CHOUTI) forControlEvents:(UIControlEventTouchUpInside)];
    
    [self.topView addSubview:self.leftButton];
    
    [self.view addSubview:self.topView];
    
    
    
    
}


//点击按钮,推出抽屉
- (void)CHOUTI
{
    
    CGRect  newFrame = self.view.frame;
    
//    CGFloat  x = 0;

    if (newFrame.origin.x ==0) {
        newFrame.origin.x = self.view.frame.size.width - 60;
//        x = 0.9;

    }else
    {
        newFrame.origin.x  = 0;
//        x = 1.0;

    }

    [UIView animateWithDuration:0.5 animations:^{
        
        
        self.view.frame = newFrame;
//        self.view.transform = CGAffineTransformMakeScale(x, x);
       
    }];
  
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //设置自定义导航view
    [self setTopView];
    
    self.tabBar.tintColor = [UIColor blackColor];
    self.tabBar.barTintColor = [UIColor colorWithWhite:0.95 alpha:0.9];
    
    
    
    //第一模块
    FirstViewController * firstVC = [[FirstViewController alloc]init];
    //第一模块导航标签 和图片
    [self addChildViewController:firstVC title:@"搞笑" image:@"" selectedImage:@""];
    
    //第二模块
    SecondViewController * secondeVC  = [[SecondViewController alloc]init];
    //第二模块导航标签 和 图片
    [self addChildViewController:secondeVC title:@"新闻" image:@"" selectedImage:@""];
    
    //第三模块
    ThirdViewController * thirdVC = [[ThirdViewController alloc]init];
    //第三模块导航标签 和图片
    [self addChildViewController:thirdVC title:@"旅游" image:@"" selectedImage:@""];
    
    //第四模块
    FourthViewController * fourthVC = [[FourthViewController alloc]init];
    //第四模块 导航标签 和图片
    [self addChildViewController:fourthVC title:@"未定" image:@"" selectedImage:@""];
   
    
}

//为tabBar 添加导航控制器
- (void)addChildViewController:(UIViewController *)childController
                         title:(NSString *)title
                         image:(NSString *)image
                 selectedImage:(NSString *)selectedImage
{
    
    UINavigationController * childVC = [[UINavigationController alloc]initWithRootViewController:childController];
    childVC.tabBarItem.title = title;
    
    //默认图片
    childVC.tabBarItem.image = [UIImage imageNamed:image];
    
    //被选中时图片
    childVC.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    
    //默认字体颜色
    NSMutableDictionary * foreDic = [NSMutableDictionary dictionary];
    foreDic[NSForegroundColorAttributeName] = [UIColor colorWithRed:123/255.0 green:123/255.0 blue:123/255.0 alpha:1.0];
    [childVC.tabBarItem setTitleTextAttributes:foreDic forState:(UIControlStateNormal)];
    
    //被选中后字体颜色
    NSMutableDictionary * selectedDic = [NSMutableDictionary dictionary];
    selectedDic[NSForegroundColorAttributeName] = [UIColor redColor];
    [childVC.tabBarItem setTitleTextAttributes:selectedDic forState:(UIControlStateSelected)];
    
    
    
    childVC.navigationBarHidden = YES;
    
    childVC.navigationBar.barTintColor = [UIColor colorWithWhite:0.95 alpha:0.8];
   
    
    [self addChildViewController:childVC];
    

    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
